package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
	jsoniter "github.com/json-iterator/go"
)

var json = jsoniter.ConfigCompatibleWithStandardLibrary

type Person struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func jsonitermain() {
	r := gin.Default()

	r.GET("/json", func(c *gin.Context) {
		p := Person{
			Name: "John",
			Age:  30,
		}
		// 使用 jsoniter 进行 JSON 序列化
		data, err := json.Marshal(p)
		if err != nil {
			c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
			return
		}
		c.Data(http.StatusOK, "application/json; charset=utf-8", data)
	})

	r.Run(":8082")
}
